home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15345 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: ix.netcom.com!news
  2. From: jhewett@ix.netcom.com (Jerry Hewett)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Did I Miss Something?
  5. Date: Thu, 04 Apr 96 18:58:38 GMT
  6. Organization: Netcom
  7. Message-ID: <N.040496.105838.83@ix.netcom.com>
  8. References: <N.040396.105136.51@ix.netcom.com>
  9.  <3163AA77.5901@cmt.lpr.mail.carel.fi>
  10. NNTP-Posting-Host: tem-ca1-08.ix.netcom.com
  11. X-NETCOM-Date: Thu Apr 04 12:58:06 PM CST 1996
  12. X-Newsreader: Quarterdeck Message Center [2.00]
  13.  
  14. Ari Lukumies <aril@cmt.lpr.mail.carel.fi> replies:
  15.  
  16. >>     Below is the constructor for "box".  The object doesn't exist until the
  17. >>     constructor creates it.  Since a pointer to a "known" fixed-length string
  18. >>     is being passed to the constructor, the compiler determines the amount of
  19. >>     memory required to store the string "small box ", allocates space for it
  20. >>     in the object, and copies it into this space.
  21. >> 
  22. >>     Once the object passes out of scope this "magically" created chunk of
  23. >>     memory allocation disappears along with the object... (???)
  24.  
  25. > Not quite - compiler does not determine and allocate anything. main() calls
  26. > the constructor with the parameter "small box". This is a constant character
  27. > string (read: array ending with a '\0') that is stored somewhere in the
  28. > memory. The assignment line_of_text = input_line simply assigns the address
  29. > of this string to line_of_text, without allocating any memory. Similarly, 
  30. >there's no destructor, so the memory is not freed, and of course should not
  31. > be, because it was not allocated by the ctor in the first place.
  32.  
  33. I've been reading through all of my reference books on C++ since I posted this 
  34. yesterday (see my previous reply to Keith Whittingham), and discovered another 
  35. major hole in my understanding of C/C++.
  36.  
  37. Due to my (obviously! :-) less than complete understanding of pointers and 
  38. string storage I was guessing that the creation of the box::small object was 
  39. performing some kind of "copy constructor" behavior -- a bitwise copy of the 
  40. object's data when the constructor was called.  This new behavior in C++ (new 
  41. to me, at least) of treating "char *" as if it were defined as "const char *", 
  42. along with the creation of a string table entry, is something I should have 
  43. apparently picked up while learning C, and is (?) covered by scope resolution.
  44.  
  45. > To make the ctor allocate some memory [...]
  46.  
  47. Errr.... "ctor"?  What's a "ctor"?
  48.  
  49. Jerry ("An Old Dog Learning New Tricks") H.
  50.  
  51.  
  52.